namespace PickGold.Charting
{
	using System;
	using System.Collections;
	using System.Collections.Specialized;

	internal static class RingTimeTrackerFactory
	{
		private static object _lockObject = new object();
		private static ListDictionary _ringTrackers = new ListDictionary();

		internal static RingTimeTracker GetRingTracker(string keyFormat)
		{
			if (_ringTrackers.Contains(keyFormat))
				return (RingTimeTracker)_ringTrackers[keyFormat];

			lock (_lockObject)
			{
				if (_ringTrackers.Contains(keyFormat))
					return (RingTimeTracker)_ringTrackers[keyFormat];

				RingTimeTracker tracker = new RingTimeTracker(ChartHttpHandler.Settings.Timeout, keyFormat, ChartHttpHandler.Settings.StorageType == ChartHttpHandlerStorageType.Cache);
				_ringTrackers.Add(keyFormat, tracker);
				return tracker;
			}
		}

		internal static IList OpenedRingTimeTrackers()
		{
			lock (_lockObject)
				return new ArrayList(_ringTrackers.Values);
		}
	}
}

